function xlow = automationlow(sbar,stilde,xup,p)

% compute maximal comparative advantage of capital relative to stilde:
xmax = fminbnd(@(x) loglaborprod(stilde,x,p)-logcapprod(x,p),0,1);

% compute xlow:
if costcomplow(sbar,stilde,xmax,xup,p)<=1 % stilde is cheaper than capital at xmax
    
    xlow = xmax;
    
else
    
    xlow = fzero(@(x) costcomplow(sbar,stilde,x,xup,p)-1,[stilde*p.stol xmax],p.optionsfzero);
    
end

end